package com.leo;

import javafx.animation.AnimationTimer;
import javafx.event.EventHandler;
import javafx.scene.input.MouseEvent;

/**
 * @ClassName MouseController
 * @Description
 * @Author wangss
 * @date 2020.11.25 16:19
 * @Version 1.0
 */
public class MouseController implements EventHandler<MouseEvent> {

    private Model model;

    private AnimationTimer animation;

    private View view;

    public MouseController(Model model, AnimationTimer animation, View view) {
        this.model = model;
        this.animation = animation;
        this.view = view;
    }

    @Override
    public void handle(MouseEvent event) {
        if (event.getEventType() == MouseEvent.MOUSE_PRESSED) {
            model.setI(model.getI() + 1);
            view.update();
            animation.start();
        } else if (event.getEventType() == MouseEvent.MOUSE_RELEASED) {
            view.clear();
            animation.stop();
        }
    }
}
